import { defineStore } from "pinia3";

export const useAppStore = defineStore(
  "app",
  () => {
    const activeName = ref<number>(0);
    const tabList = ref<any[]>([]);
    function setActiveName(value: number) {
      activeName.value = value;
    }
    function setTabList(value: any[]) {
      tabList.value = value;
    }
    async function fetchTabList() {
      const timer = setTimeout(() => {
        clearTimeout(timer);
        setTabList([
          { title: "Home", name: 0 },
          { title: "Timetable", name: 1 },
          { title: "News", name: 2 }
        ]);
      }, 300);
    }
    return {
      activeName,
      tabList,
      setActiveName,
      setTabList,
      fetchTabList
    };
  },
  {
    // persist: {
    //   storage: sessionStorage,
    // },
    persist: false
  }
);

// import { useAppStore } from "@/store";
// import { storeToRefs } from "pinia3";
// const appStore = useAppStore();
// const { activeName, tabList } = storeToRefs(appStore);
// onMounted(() => {
//   appStore.fetchTabList();
// });
